
package src;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author administrador
 */
public class WriteProprierts
{

    public static String VERSION = "version";
    public static String NAME = "name";
    public static String EMAIL = "email";
    public static String RANKING = "rank";
    public static String DEBUG = "log";
    public static String ERRORS = "error";
    public static String STARTKEY = "key";
    String dir = null;

    void WritePorprierts()
    {
    }

    public void getDir()
    {
        String patch =  ( getClass().getResource("/res/dir.txt") ).getPath();
        dir = patch.substring(0,patch.indexOf("QuicklyTranslator.jar"));
        //dir = patch.substring(0,patch.indexOf("src"));

        System.out.println(dir);
    }

    public String read( String whattosave )
    {
        getDir();
        FileInputStream fin;
        String result = null;

        try
        {
            File file = new File( "" + dir + File.separator + whattosave + ".dat" );

            fin = new FileInputStream( file.getCanonicalPath() );

            result = new DataInputStream( fin ).readLine();
            //System.out.println( "Reading file: " + file.getCanonicalPath() + " " + result );
            fin.close();
        }
        catch ( IOException e )
        {
            Degub.getInstance().Debug( "Unable to read from file" );
            Degub.getInstance().Debug( "File losed: " + whattosave );
        }

        if ( result == null )
        {
            result = "0";
        }

        Degub.getInstance().Debug( "Reading: " + whattosave + " readed " + result );

        return result;

    }

    public void write( String whatToWrite, String txt )
    {
        getDir();
        FileOutputStream fin;

        try
        {
            File file = new File( "" + dir + File.separator + whatToWrite + ".dat" );

            //System.out.print( "-" + file.getAbsolutePath() );

            if ( ! file.exists() )
            {
                file.createNewFile();
            }

            fin = new FileOutputStream( file.getCanonicalPath() );

            new PrintStream( fin ).println( txt );

            fin.close();
        }
        catch ( IOException e )
        {
            //System.out.println( "File losed: " + whatToWrite );
        }

    }

    public static void main( String[] args )
    {

    }
}
